from flask import Flask, render_template, flash, redirect, url_for
from forms import LoginForm
app = Flask(__name__)
app.config['SECRET_KEY'] = '!@#$$#~~WDNFJDI~@@(($#'

'''
import os
class Config(object):
    SECRET_KEY = os.environ.get('SECRET_KEY')
'''


@app.route('/')
def hello_world():
    return 'Hello World!'


@app.errorhandler(404)
def not_found_error(error):
    return render_template('404.html'), 404

@app.route('/index')
def index():
    user = {"username":'lili'}
    posts = [{
        'author':{'username':'John'},
        'body':"What a beautiful day!"},
        {'author': {'username':'Lucy'},
    'body': 'I like this conment!'
    }]
    return render_template('index.html',title='LL' , user= user, posts = posts)

@app.route('/login', methods=['GET', 'POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        flash('Login requested for user {}, remrember_me={}'.format(form.username.data,form.remember_me.data))
        return redirect(url_for('index'))
    return render_template('login.html', title='Sign In', form=form)

if __name__ == '__main__':
    app.run(debug=True)
